$(function () {
    //上个页面带过来的id
    var orderBillId = $("#orderBillId").val();
    //发送请求查询数据进行回显
    $.post("/client/selectByOrderBillId?orderBillId=" +orderBillId , function (data) {
        if(data){
            $("#client_form").form("load",data);
        }
    });
    $.post("/clientCar/selectByOrderBillId?orderBillId=" + orderBillId,function (data) {
        if(data){
            $("#car_form").form("load",data);
        }
    });
    $.post("/orderBill/selectByOrderBillId?orderBillId=" + orderBillId,function (data) {
        if(data.aplicant){
            data["aplicant.realname"] = data.aplicant.realname;
        }
        if(data){
            $("#time_form").form("load",data);
            $("#revise_form").form("load",data);
        }
    });
    $.post("/reviseinfo/selectReviseinfo?orderBillId="+ orderBillId,function (data) {
        if(data){
            $("#revise_form").form("load",data);
        }
    });

    $("#revise-panel").panel({
        title: "批改页面外框",
        fit:true
    });
    $("#reviseinfo_panel").panel({
        title: "核保信息",
        collapsible:true
    });
    $("#client_panel").panel({
        title: "投保人信息",
        collapsible:true
    });
    $("#time_panel").panel({
        title: "时间信息",
        collapsible:true
    });
    $("#car_panel").panel({
        title: "车辆信息",
        collapsible:true,
        //发送请求查询数据进行回显 (行不通)
        //content:'<iframe src="/client/selectByOrderBillId?orderBillId=" + ${orderBillId} style="width:100%;height:100%" frameborder="0"></iframe>
    });
    //二级联动
    $('#selectedBrand').combobox({
        onSelect: function (row) {
            if (row != null) {
                $('#selectedModel').combobox({
                    url: "/carModel/selectChildByParentId?parentId=" + row.id
                });
            }
        }
    });
    //保存 和 提交审核
    $("a[data-cmd]").on("click",function(){
        var way = $(":input[name='way']").val();
        var cmd = $(this).data("cmd");
        var url;
        var param;
        if(way == 1){
            url = '/underWriting/pass?orderBillId=' + orderBillId;
            param = "comments";
        } else if(way == 2){
            url = '/underWriting/notPass?orderBillId=' + orderBillId;
            param = "suggestions";
        }

        if(cmd == 'save'){
            var info = $(":input[name='info']").val();
            $.post("/underWriting/temp?underWritingId="+$("#underWritingId").val(),{comments:info},function(data){
                if(data.success){
                    $.messager.alert("温馨提示",data.msg,"info");
                }else{
                    $.messager.alert("温馨提示",data.msg,"error");
                }
            },"json");
        }
        if (cmd == 'submit'){
            $.messager.confirm("温馨提示","请确定是否继续此操作?",function(yes) {
                if (yes) {
                    var info = $(":input[name='info']").val();
                    $.post(url + "&underWritingId=" + $("#underWritingId").val(), {param: info}, function (data) {
                        if (data.success) {
                            window.location.href = '/pending_approval';
                            // window.history.back(-1);
                            $.messager.alert("温馨提示", data.msg, "info");
                        } else {
                            $.messager.alert("温馨提示", data.msg, "error");
                        }
                    }, "json");
                }
            });
        }





        // var cmd = $(this).data("cmd");
        // var  url = "/temporaryTask/save";
        // if(cmd == "submit"){
        //     url = "/reviseinfo/save?status=7";
        // }
        // $("#revise_form").form("submit",{
        //     url:url,
        //     success: function(data) {
        //         data = $.parseJSON(data);
        //         if(data.success){
        //             $("#car_form").form("submit",{
        //                 url:"/clientCar/reviseCar",
        //                 success: function(data) {
        //                     data = $.parseJSON(data);
        //                     if(data.success){
        //                         $("#client_form").form("submit",{
        //                             url:"/client/update",
        //                             success: function(data) {
        //                                 data = $.parseJSON(data);
        //                                 if(data.success){
        //                                     $.messager.alert("温馨提示",data.msg,"info");
        //                                 }
        //                             }
        //                         });
        //                     }
        //                 }
        //             });
        //         }
        //     }
        // });
    });
});